package com.assignwork.dto;

import com.assignwork.entity.DynamicForm;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import org.springblade.core.tool.utils.Func;

import java.time.LocalDate;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * DynamicFormDTO
 */
@Data
@ApiModel(value = "DynamicFormDTO对象", description = "动态表单")
public class DynamicFormDTO extends DynamicForm {

    private List<DynamicFormDataDTO> data;

    @Override
    public String getColumnsKey() {
        if (Func.isNotEmpty(data)) {
            return data.stream().map(DynamicFormDataDTO::getDataColumn).collect(Collectors.joining(","));
        }
        return super.getColumnsKey();
    }

    @Override
    public String getRowsKey() {
        if (Func.isNotEmpty(data)) {
            return data.stream().map(DynamicFormDataDTO::getDataRow).collect(Collectors.joining(","));
        }
        return super.getRowsKey();
    }

    public List<DynamicFormDataDTO> getData() {
        if (getId() != null) {
            Long id = getId();
            return data.stream().map(i -> {
                i.setFormId(id);
                return i;
            }).collect(Collectors.toList());
        }
        return data;
    }
}